<%@page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" %>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>登录界面</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div id="app" class="container">
    <div class="row">
        <div class="col-md-4"></div>
        <%--<form action="/demo/design/addClassCourse" method="post">--%>
        <div class="col-md-4">
            <p class="h1 text-center">班级课程增加</p>
            <div>
                <input type="text" name="grade" class="form-control" v-model="classCourseM.grade" placeholder="班级">
            </div>
            <br>
            <div>
                <input type="text" name="major" class="form-control" v-model="classCourseM.major" placeholder="系科">
            </div>
            <br>
            <div>
                <input type="text" name="year" class="form-control" v-model="classCourseM.year" placeholder="学制">
            </div>
            <br>
            <div>
                <input type="text" name="term" class="form-control" v-model="classCourseM.term" placeholder="入学时间">
            </div>
            <br>
            <select class="form-control" v-model="classCourseM.selectCourse" @change="getSelected">
                <option value="请选择课程" disabled selected hidden>请选择课程</option>
                <option v-for="(courseM,i) in courseMs" :value="courseM.name">{{courseM.name}}</option>
            </select>
            <%--<div>--%>
            <%--<input type="text" name="selectCourse" class="form-control" v-model="classCourseM.selectCourse" placeholder="需学课程">--%>
            <%--</div>--%>
            <br>
            <button type="submit" @click="add()" class="btn btn-info btn-block" >提交</button>
        </div>
        <%--</form>--%>
        <div class="col-md-4">
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<script src="/static/js/vue.js"></script>
<script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            name:'',
            classCourseM: {
                grade: null,
                major: '',
                year: null,
                term: null,
                selectCourse: '',
            },
            courseMs:[],
        },
        created(){
            this.classCourseM.selectCourse = '请选择课程';
        },
        methods: {
            getSelected(){
                console.log(this.classCourseM.selectCourse);
            }
            ,
            getName:function () {
                $.ajax({
                    url:'/demo/course/get',
                    type:'GET',
                    data:{name:this.name},
                    dataType:'json',
                    success:function(result){
                        app.courseMs = result;
                    }
                });
            },
            add:function () {
                $.ajax({
                    url:'/demo/design/addClassCourse',
                    type:'POST',
                    data:JSON.stringify(this.classCourseM),
                    contentType:'application/json',
                    success:function(result){
                        this.result = result;
                        var url = '/demo/design/index';
                        if(result.indexOf("成功")>=0){
                            window.location.href='/demo/stuInfo/success?result='+this.result+'&url=' + url;
                        }else{
                            window.location.href= '/demo/stuInfo/error?result='+this.result+'&url=' + url;
                        }
                    }
                });
            }
        }
    });
    $(function () {
        app.getName();
    })
</script>
</body>
</html>